package main.java.com.chenchangjie.utils;

import java.sql.*;

public class JDBCUtil {

    public static Connection getConnection() throws SQLException {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
// 加载驱动类
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        long start = System.currentTimeMillis();

        // 建立连接
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cart?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT",
                "root", "root");

        return conn;
    }

    public static void Close(ResultSet resultSet, PreparedStatement statement,Connection connection) throws SQLException {
        if(resultSet != null)
            resultSet.close();
        if(statement != null)
            statement.close();
        if(connection != null)
            connection.close();
    }
}
